package com.seeyon.apps.kk.controller;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.seeyon.apps.kk.manager.BatchProcessingManagerImpl;
import com.seeyon.apps.kk.manager.OrgSyncEmailManagerImpl;
import com.seeyon.apps.uc.rongcloud.utils.DateUtil;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.authenticate.domain.User;

/**
 * 待办事项 批处理权限设置
 * 
 * @author seeyon
 *
 */
public class BatchProcessingController extends KkBaseController {

	private BatchProcessingManagerImpl managerImpl = (BatchProcessingManagerImpl) AppContext
			.getBean("batchProcessingManagerImpl");

	private OrgSyncEmailManagerImpl emailManagerImpl = (OrgSyncEmailManagerImpl) AppContext
			.getBean("orgSyncEmailManagerImpl");

	/**
	 * 获取当前登录人员Id 检测是否具有批处理角色权限
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView checkRole(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView(ROOT_PATH + "/json/checkDone");
		User user = AppContext.getCurrentUser();
		Map<String, Object> map = Maps.newHashMap();
		map.put("memberId", user.getId().toString());
		map.put("result", managerImpl.checkBatchProcessingRoleByMemberId(map));
		mav.addObject("result", JSON.toJSONString(map));
		return mav;
	}

	/**
	 * 获取email未读邮件消息
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView getEmail(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView(ROOT_PATH + "/json/checkDone");
		User user = AppContext.getCurrentUser();
		emailManagerImpl.sendMsg(user.getLoginName());
		mav.addObject("result", JSON
				.toJSONString("get email message is ok !" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
		return mav;
	}
}
